package com.dj.ssm.web;


import com.dj.ssm.entity.ExamQ;
import com.dj.ssm.entity.Examinee;
import com.dj.ssm.service.ExamService;
import com.dj.ssm.service.dto.ExamDto;
import com.dj.ssm.util.DozerUtil;
import com.dj.ssm.util.ResultModel;
import com.dj.ssm.web.vo.ExamVoReq;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/exam")
public class ExamController {
    @Autowired
    private ExamService examService;

    /**
     * 考试展示
     * @return
     */
    @RequestMapping("/show")
    public ResultModel list(){
        List<ExamQ> exam = examService.queryAll();
        return new ResultModel().success(exam);
    }

    @RequestMapping("/userList")
    public ResultModel userList(Integer examId){
        List<Examinee> exam = examService.queryUser(examId);
        return new ResultModel().success(exam);
    }

    @RequestMapping("/insert")
    public ResultModel insert(ExamVoReq examVoReq){
        ExamDto examDto =  DozerUtil.map(examVoReq, ExamDto.class);
        examService.insertAll(examDto);
        return new ResultModel().success();
    }

    @RequestMapping("/del/{neeId}")
    public ResultModel del(@PathVariable Integer neeId){
        examService.deleteById(neeId);
        return new ResultModel().success();
    }

    /**
     * 考生录入
     * @param
     * @return
     */
    @RequestMapping("/insertUser")
    public ResultModel insertUser(Examinee examinee, Integer examId){
        examService.insertUser(examinee, examId);
        return new ResultModel().success();
    }
}
